package com.rzj.book.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.rzj.book.en.Dep;
import com.rzj.book.service.IDepService;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description:
 * @author: rzj
 * @time: 2020/6/11 22:27
 */
@RestController
@RequestMapping("/dep")
public class DepController extends BaseController {

    @Autowired
    private IDepService depService;

    @RequestMapping("/getDepCommbox")
    public String getDepCommbox() {
        List<Dep> depList = depService.getDepCommbox();
        JSONArray jsonArray = new JSONArray();
        jsonArray.add(new JSONObject().element("id", "").element("text", "请选择"));
        for (Dep item : depList) {
            jsonArray.add(new JSONObject().element("id", item.getDepId()).element("text", item.getName()));
        }
        write(JSON.toJSONString(jsonArray));
        return null;
    }
}
